<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <title>Vue3 Demo</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>
<div id="Application" style="text-align:center;">
    <h1>{{ title }}</h1>
    <div v-if="noLogin">账号：<input v-model="userName" type="text"/></div>
    <div v-if="noLogin">密码：<input v-model="password" type="password"/></div>
    <div v-on:click="click" style="border-radius:30px;width:100px;margin:20px auto;color:white;background-color:blue;">
        {{ buttonTitle }}
    </div>
</div>
</body>
<script>
    const App = {
        // 数据
        data() {
            return {
                title: '欢迎您：未登录',
                noLogin: true,
                userName: '',
                password: '',
                buttonTitle: '登录'
            }
        },
        // 登录方法
        methods: {
            // 登录
            click() {
              if (this.noLogin){
                  this.login()
              } else {
                  this.logout()
              }
            },
            login() {
                // 验证登录
                if (this.userName.length > 0 && this.password.length > 0) {
                    this.noLogin = false;
                    this.title = "欢迎你" + this.userName;
                    this.buttonTitle = "注销"
                    this.userName = "";
                    this.password = "";
                } else {
                    alert("请输入账号密码！")
                }
            },
            logout() {
                this.noLogin = true;
                this.buttonTitle = "登录";
                this.title = "欢迎你：未登录";
            }
        }
    }
    Vue.createApp(App).mount('#Application');
</script>
</html>